package address

import (
	"net/http"

	"laundry-service/app/client/internal/logic/address"
	"laundry-service/app/client/internal/svc"
	"laundry-service/app/client/internal/types"
	"laundry-service/common"

	"github.com/zeromicro/go-zero/rest/httpx"
)

func CreateAddressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.CreateAddressReq
		if err := httpx.Parse(r, &req); err != nil {
			httpx.Error(w, common.NewErrResponse(200, err.Error()))
			return
		}

		l := address.NewCreateAddressLogic(r.Context(), svcCtx)
		resp, err := l.CreateAddress(&req)
		if err != nil {
			httpx.Error(w, common.NewErrResponse(200, err.Error()))
		} else {
			httpx.OkJson(w, common.NewSuccessResponse(resp))
		}
	}
}
